This is the technical documentation page.

A copy or clone of FreeCodeCamp Project.

Lets get started.

Introduction

JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user.
JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators,
control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects;
for example:

  • Client-side JavaScript extends the core language by supplying objects to control a browser and its Document Object Model (DOM).
    For example, client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks,
    form input, and page navigation.
  • Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server.
    For example, server-side extensions allow an application to communicate with a database, provide continuity of information from one invocation to another of the application,
    or perform file manipulations on a server.

Pre-Requisites For JS

A person should have a knowledge of the following basic things before he starts learning JS:

  1. A general understanding of the Internet and the World Wide Web (WWW).
  2. Knowledge of Hyper Text Markup Language(HTML). A very important foundation of web development.
  3. Some programming experience. If you are new to programming, try one of the tutorials linked on the main page about JavaScript.
JavaScript & Java

JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking.
JavaScript follows most Java expression syntax, naming conventions and basic control-flow constructs
which was the reason why it was renamed from LiveScript to JavaScript.
In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead of the more common class-based object model.
The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects.
JavaScript also supports functions without any special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
avaScript is a very free-form language compared to Java. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected,
and you do not have to implement interfaces. Variables, parameters,
and function return types are not explicitly typed.

Hello World Program

Writing code in javaScript is very easy. like we can easily write a code for
printing Hello World in JS. The syntax is given below:

function Name(name) { alert(" The name of the person is --> "+ name); } Name("Mukarram Asad");
Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.
A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9).
Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). You can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can also use the Unicode escape sequences as characters in identifiers.

Declaring Variables in JS

There are about 5 data types for variables in javaScript, anmely:

  1. Number
  2. String
  3. Boolean
  4. Undefined
  5. Object
we can easily declare a variable in javaScript as follows:

var a = 10; // Number data type. var b = '120'; // String data type. var c = true; // Boolean data type. var d = undefined; // undefined data type.
Variables Scope

The scope of the variables in javaScript is categorized in two types:

  1. Global Scope Variables.
  2. Local Scope Variables.

The variables used inside a function are known as Local Scope Variables.
While the variables which are declare in main code are known as Global Scope variables.

var a = 10; function foo() { var b; a = 12; b = 5; console.log(a + ' ' + b); }
Conditional Statements in JS

Use the if statement to execute a statement if a logical condition is true. Use the optional else clause to execute a statement
if the condition is false. An if statement looks as follows:

if (condition) { statement_1; } else { statement_2; }

The example of if-else staement in javaScript is as follows:

var a = 10; if(a > 5) { alert("You Win"); } else { alert("You Lose"); }
Switch Statement in JS

Switch statement is simply an alternative of multiple if-else statements. It is very common in finding days, month
years etc. The code structure of switch statement is given as follows:

switch(element Name) { case (matching part) { // some code } case (matching part) { // some code } default { // Some code over here too. } }

The example of if-else staement in javaScript is as follows:

var a = prompt("Enter your favourite number:"); switch(a) { case('1') { alert(" You are so nice.") } case('2') { alert(" You are so intelligent.") } case('3') { alert(" You are so strong.") } default { alert("You are all rounder"); } }
While Loop in JS

A while statement executes its statements as long as a specified condition evaluates to true. A while statement looks as follows:
while (condition) statement If the condition becomes false, statement within the loop stops executing and control passes to the statement following the loop.
The condition test occurs before statement in the loop is executed. If the condition returns true, statement is executed and the condition is tested again.
If the condition returns false, execution stops and control is passed to the statement following while. To execute multiple statements, use a block statement ({ ... }) to group those statements.

Functions in JS

A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:

  • The name of the function.
  • A list of arguments to the function, enclosed in parentheses and separated by commas.
  • The JavaScript statements that define the function, enclosed in curly brackets, { }.